<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.js.fan.util.*" %>
<%@ page import="java.util.*" %>
<%@ page import="cn.js.fan.web.*" %>
<%@ page import="com.redmoon.oa.visual.*" %>
<%@ page import="com.redmoon.oa.flow.*" %>
<%@ page import="com.redmoon.oa.ui.*" %>
<jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
<%
    String priv = "read";
    if (!privilege.isUserPrivValid(request, priv)) {
        out.print(SkinUtil.makeErrMsg(request, SkinUtil.LoadString(request, "pvg_invalid")));
        return;
    }

    String op = ParamUtil.get(request, "op");

    String formCode = ParamUtil.get(request, "formCode"); // 主模块编码
    if (formCode.equals("")) {
        out.print(SkinUtil.makeErrMsg(request, "编码不能为空！"));
        return;
    }

    String moduleCodeRelated = ParamUtil.get(request, "moduleCodeRelated"); // 从模块编码
    String menuItem = ParamUtil.get(request, "menuItem");
    String moduleCode = ParamUtil.get(request, "code");

    ModuleSetupDb msd = new ModuleSetupDb();
    msd = msd.getModuleSetupDbOrInit(moduleCodeRelated);
    if (msd == null) {
        out.print(cn.js.fan.web.SkinUtil.makeErrMsg(request, "模块不存在！"));
        return;
    }
    String formCodeRelated = msd.getString("form_code");

    ModulePrivDb mpd = new ModulePrivDb(moduleCodeRelated);
    if (!mpd.canUserModify(privilege.getUser(request))) {
%>
    <link type="text/css" rel="stylesheet" href="<%=SkinMgr.getSkinPath(request)%>/css.css"/>
<%
        out.print(cn.js.fan.web.SkinUtil.makeErrMsg(request, cn.js.fan.web.SkinUtil.LoadString(request, "pvg_invalid")));
        return;
    }

    int id = ParamUtil.getInt(request, "id");
    // 置嵌套表需要用到的cwsId
    request.setAttribute("cwsId", "" + id);
    // 置页面类型
    request.setAttribute("pageType", "edit");

    // 用于表单域选择窗体宏控件
    request.setAttribute("formCode", formCodeRelated); // 这里是为了使嵌套表在getNestSheet方法中，传递给当前编辑的表单中的嵌套表

    int parentId = ParamUtil.getInt(request, "parentId", -1); // 父模块的ID，仅用于导航，如果导航不显示，则不用传递该参数，用例：module_show_realte.jsp编辑按钮

    FormMgr fm = new FormMgr();
    FormDb fd = fm.getFormDb(formCodeRelated);

    request.setAttribute("formCodeRelated", formCodeRelated);

    com.redmoon.oa.visual.FormDAOMgr fdm = new com.redmoon.oa.visual.FormDAOMgr(fd);

    int isShowNav = ParamUtil.getInt(request, "isShowNav", 0);

    String tabIdOpener = ParamUtil.get(request, "tabIdOpener");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>智能设计-编辑内容</title>
    <meta name="renderer" content="ie-stand">
    <link type="text/css" rel="stylesheet" href="<%=SkinMgr.getSkinPath(request)%>/css.css"/>
    <script src="../inc/common.js"></script>
    <script type="text/javascript" src="../js/jquery1.7.2.min.js"></script>
    <script src="../js/jquery-alerts/jquery.alerts.js" type="text/javascript"></script>
    <script src="../js/jquery-alerts/cws.alerts.js" type="text/javascript"></script>
    <link href="../js/jquery-alerts/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen"/>
    <script src="../js/jquery.raty.min.js"></script>
    <script src="../inc/livevalidation_standalone.js"></script>
    <script src="../inc/upload.js"></script>
    <script src="../inc/flow_dispose_js.jsp"></script>
    <script src="../inc/flow_js.jsp"></script>
    <script src="../inc/ajax_getpage.jsp"></script>

    <script src="../flow/form_js/form_js_<%=formCodeRelated%>.jsp?pageType=edit&id=<%=id%>"></script>

    <link rel="stylesheet" type="text/css" href="../js/datepicker/jquery.datetimepicker.css"/>
    <script src="../js/datepicker/jquery.datetimepicker.js"></script>

    <link href="../js/select2/select2.css" rel="stylesheet"/>
    <script src="../js/select2/select2.js"></script>
    <script src="../js/select2/i18n/zh-CN.js"></script>

    <!--
<style type="text/css"> 
@import url("<%=request.getContextPath()%>/util/jscalendar/calendar-win2k-2.css"); 
</style>

<script type="text/javascript" src="<%=request.getContextPath()%>/util/jscalendar/calendar.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/util/jscalendar/lang/calendar-zh.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/util/jscalendar/calendar-setup.js"></script>
 -->

    <script>
        $(function () {
            SetNewDate();
        });

        function setradio(myitem, v) {
            var radioboxs = document.all.item(myitem);
            if (radioboxs != null) {
                for (i = 0; i < radioboxs.length; i++) {
                    if (radioboxs[i].type == "radio") {
                        if (radioboxs[i].value == v)
                            radioboxs[i].checked = true;
                    }
                }
            }
        }

        function SubmitResult() {
            // 检查是否已选择意见
            if (getradio("resultValue") == null || getradio("resultValue") == "") {
                jAlert("您必须选择一项意见!", "提示");
                return false;
            }
            visualForm.op.value = 'finish';
            visualForm.submit();
        }

        // 控件完成上传后，调用Operate()
        function Operate() {
            // alert(redmoonoffice.ReturnMessage);
        }
    </script>
</head>
<body>
<%
    if (op.equals("saveformvalue")) {
        boolean re = false;
        try {
            re = fdm.update(application, request);
        } catch (ErrMsgException e) {
            out.print(StrUtil.jAlert_Back(e.getMessage(), "提示"));
            return;
        }
        if (re) {
%>
<script>
    reloadTab("<%=tabIdOpener%>");
    // 如果有父窗口，则自动刷新父窗口
    if (window.opener != null) {
        window.opener.location.reload();
        window.opener.focus();
        window.close();
    }
</script>
<%
            out.print(StrUtil.jAlert_Redirect("操作成功！", "提示", request.getRequestURL() + "?code=" + StrUtil.UrlEncode(moduleCode) + "&parentId=" + parentId + "&id=" + id + "&menuItem=" + menuItem + "&formCodeRelated=" + formCodeRelated + "&formCode=" + StrUtil.UrlEncode(formCode) + "&isShowNav=" + isShowNav + "&moduleCodeRelated=" + moduleCodeRelated));
        } else
            out.print(StrUtil.jAlert_Back("操作失败！", "提示"));
        return;
    } else if (op.equals("delAttach")) {
        int attachId = ParamUtil.getInt(request, "attachId");
        com.redmoon.oa.visual.Attachment att = new com.redmoon.oa.visual.Attachment(attachId);
        if (att.isLoaded()) {
            att.del();
        }
    }
    if (isShowNav == 1) {
%>
<%@ include file="module_inc_menu_top.jsp" %>
<script>
    o("menu<%=menuItem%>").className = "current";
</script>
<div class="spacerH"></div>
<%
    } else
        out.print("<BR>");
%>
<form action="module_edit_relate.jsp?op=saveformvalue&id=<%=id%>&menuItem=<%=menuItem%>&parentId=<%=parentId%>&code=<%=StrUtil.UrlEncode(moduleCode)%>&formCodeRelated=<%=formCodeRelated%>&formCode=<%=StrUtil.UrlEncode(formCode)%>&isShowNav=<%=isShowNav%>&moduleCodeRelated=<%=moduleCodeRelated%>&tabIdOpener=<%=tabIdOpener%>" method="post"
      enctype="multipart/form-data" name="visualForm" id="visualForm">
    <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td align="left">
                <table width="100%">
                    <tr>
                        <td><%
                            com.redmoon.oa.visual.Render rd = new com.redmoon.oa.visual.Render(request, id, fd);
                            out.print(rd.rend(msd));
                        %>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <%if (fd.isHasAttachment()) {%>
        <tr>
            <td align="left">
                <script>initUpload()</script>
            </td>
        </tr>
        <tr>
            <td align="left"><%
                com.redmoon.oa.visual.FormDAO fdao = fdm.getFormDAO(id);
                Iterator ir = fdao.getAttachments().iterator();
                while (ir.hasNext()) {
                    com.redmoon.oa.visual.Attachment am = (com.redmoon.oa.visual.Attachment) ir.next(); %>
                <table width="82%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="5%" height="31" align="right"><img src="<%=Global.getRootPath()%>/images/attach.gif"/></td>
                        <td>
                            &nbsp; <a target="_blank" href="<%=Global.getRootPath()%>/visual_getfile.jsp?attachId=<%=am.getId()%>"><%=am.getName()%></a>&nbsp;&nbsp;&nbsp;&nbsp;
                            [<a href="#" onClick="jConfirm('您确定要删除吗？','提示',function(r){if(!r){return;}else{window.location.href='?op=delAttach&parentId=<%=parentId%>&id=<%=id%>&formCode=<%=StrUtil.UrlEncode(formCode)%>&formCodeRelated=<%=formCodeRelated%>&attachId=<%=am.getId()%>&moduleCodeRelated=<%=moduleCodeRelated%>'}}) " style="cursor:pointer">删除</a>]<br/></td>
                    </tr>
                </table>
                <%}%></td>
        </tr>
        <%}%>
        <tr>
            <td height="30" align="center"><input name="id" value="<%=id%>" type="hidden"/>
                <input type="submit" class="btn" name="Submit" value=" 修改 "/>
                &nbsp;&nbsp;
                <%if (isShowNav == 0) {%>
                <%--<input type="button" class="btn" value=" 返回 " onClick="window.history.back()"/>--%>
                <%}%>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
